package com.tuantuan.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tuantuan.model.UserOrder;
import com.tuantuan.model.Users;
import com.tuantuan.service.UsersService;
import com.tuantuan.utils.UntilEntity;
/**
 * 基本用户操作控制层
 * @author Administrator
 *
 */
@Controller
public class UserController {

	@Resource(name = "UsersService")
	private UsersService userService;
	/**
	 * 登录账号密码校验
	 */
	@RequestMapping("/users/userLogin.do")
	@ResponseBody
	public String userLogin(Users u,HttpServletRequest req){
		UntilEntity<Users> usersEntity = userService.queryLogin(u);
		//req.setAttribute("loginFlag", usersEntity.getRemark());
		if("success".equals(usersEntity.getRemark())){
			req.getSession().setAttribute("userEntity", usersEntity.getEntity());
			return  usersEntity.getRemark();
		}
		return  usersEntity.getRemark();
	}
	@RequestMapping("/users/userUpdate.do")
	@ResponseBody
	public String userUpdate(UserOrder u,HttpServletRequest req){
		
		return userService.updateUser(u);
		
	}
	@RequestMapping("/users/userExit.do")
	private String toUserExit(HttpServletRequest request){
		request.getSession().removeAttribute("userEntity");
		return "users/login";
	}

	public UsersService getUserService() {
		return userService;
	}

	public void setUserService(UsersService userService) {
		this.userService = userService;
	}
	

}
